﻿using MediatR;
using SU.Center.Domain.RBAC;
using SU.Center.Infa;

namespace SU.Center.Api.Handler.RBAC
{
    /// <summary>
    /// 获取用户列表
    /// </summary>
    public class GetUSerListHandler : IRequestHandler<GetUSerListReqsultDto, ApiResult>
    {
        private readonly IBaseReposiotry<UserInfo> baseReposiotry;
        private readonly IBaseReposiotry<UserRoles> reposiotry;

        public GetUSerListHandler(IBaseReposiotry<UserInfo> baseReposiotry, IBaseReposiotry<UserRoles> reposiotry)
        {
            this.baseReposiotry = baseReposiotry;
            this.reposiotry = reposiotry;
        }

        public async Task<ApiResult> Handle(GetUSerListReqsultDto request, CancellationToken cancellationToken)
        {
            var list = await baseReposiotry.GetAll();
            var user = await reposiotry.GetAll();

            var query = from aber in list
                        join ber in user on aber.UserInfoId equals ber.UserInfoId
                        select new GetUSerListReopsultDto()
                        {
                            UserName = aber.UserName,
                            RolesId = ber.RolesId
                        };

            return ApiResult.Ok(query);
        }
    }
}

public class GetUSerListReqsultDto : IRequest<ApiResult>
{

}

public class GetUSerListReopsultDto
{
    public string UserName { get; set; }
    public int RolesId { get; set; }
}
